package com.yixun.qfbao.hander;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.model.PartnerInfo;
import com.yixun.qfbao.model.dto.CompanyDto;
import com.yixun.qfbao.service.CompanyService;
import com.yixun.qfbao.utils.LoginUtils;
import com.yixun.qfbao.vo.SavePartnerCheckRuleReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;

/**
 * @author zilong.liu
 * @date 2020-12-16
 *
 * desc:
 *     	根据用户ID获取对应保存人员审核规则
 */
@Service("savePartnerCheckRuleHander")
public class SavePartnerCheckRuleHander extends CommonAbstractHander{

	@Autowired
	CompanyService companyService;
	
	@Autowired
	LoginUtils loginUtils;
	
	@Override
	@SuppressWarnings("rawtypes")
	public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
		SavePartnerCheckRuleReqVo reqVo = (SavePartnerCheckRuleReqVo) reqDto;
		String userId = reqVo.getParams().getUserId();
		PartnerInfo partnerInfo = loginUtils.getUser(userId);
		Long companyId = partnerInfo.getHigherid();
		
		String enablePartnerCheck = reqVo.getParams().getEnablePartnerCheck();
		
		CompanyDto entity = new CompanyDto();
		entity.setId(companyId);
		entity.setEnablePartnerCheck(enablePartnerCheck);
		int result = companyService.update(entity);
		
		BaseResponseDTO res = new BaseResponseDTO();
		res.setResData(result == 1? "保存成功": "保存失败");
		res.setResult(result == 1? ResultEnum.SUCCESS.getNo(): ResultEnum.FAIL.getNo());
		return res;
	}

}
